package com.mall.orders.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.utils.CommonResult;
import com.mall.model.domain.OmsOrderReturnReason;
import com.mall.model.vo.CommonPage;
import com.mall.orders.service.OmsOrderReturnReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 退货原因表(OmsOrderReturnReason)表控制层
 *
 * @author wishmumu
 * @since 2023-03-11 15:42:55
 */
@RestController
@RequestMapping("returnReason")
public class OmsOrderReturnReasonController extends ApiController {
    /**
     * 服务对象
     */
    @Autowired
    private OmsOrderReturnReasonService omsOrderReturnReasonService;

    /**
     * 分页查询所有数据
     * @return 所有数据
     */
    @GetMapping("/list")
    public CommonResult selectAll(Integer pageNum, Integer pageSize) {
        CommonPage page = omsOrderReturnReasonService.selectAll(pageNum, pageSize);
        return CommonResult.success(page);
    }

    /**
     * 获取单个退货原因详情信息
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public CommonResult selectOne(@PathVariable("id") Integer id) {
        OmsOrderReturnReason omsOrderReturnReason = omsOrderReturnReasonService.getById(id);
        return CommonResult.success(omsOrderReturnReason);
    }

    /**
     * 添加退货原因
     * @param omsOrderReturnReason 实体对象
     * @return 新增结果
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody OmsOrderReturnReason omsOrderReturnReason) {
        omsOrderReturnReasonService.save(omsOrderReturnReason);
        return CommonResult.success("success");
    }

    /**
     * 修改退货原因
     * @param returnReason 实体对象
     * @return 修改结果
     */
    @PostMapping("/update/{id}")
    public CommonResult updateById(@PathVariable("id") Integer id, @RequestBody OmsOrderReturnReason returnReason) {
        omsOrderReturnReasonService.updateById(id, returnReason);
        return CommonResult.success("Success");
    }

    /**
     * 修改退货原因启用状态
     * @param ids
     * @param status
     * @return
     */
    @PostMapping("/update/status")
    public CommonResult updateStatus(@RequestParam ArrayList<Integer> ids,Integer status) {
        omsOrderReturnReasonService.updateStatus(ids, status);
        return CommonResult.success("Success");
    }
    /**
     * 批量删除退货原因
     * @param ids 主键结合
     * @return 删除结果
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam("ids") List<Integer> ids) {
        omsOrderReturnReasonService.removeByIds(ids);
        return CommonResult.success("Success");
    }
}

